<template>
    <div class="login">
       <el-input v-model="username" placeholder="请输入内容"></el-input>
       <el-input placeholder="请输入密码" v-model="password" show-password></el-input>
       <el-button @click="submit">登录</el-button>
    </div>
</template>

<script>
import store from '@/store';
import {Message} from 'element-ui';
export default {
    data(){
        return {
            username:'',
            password:''
        }
    },
    methods:{
        async submit(){
            const {username,password} = this;
            const res = await store.dispatch('users/login',{username,password});
            Message({
                    type:res.code === 1? 'success' : 'error',
                    message:res.msg,
                    duration:2000
                })
            if(Object.is(res.code,1)) this.$router.push({path:'/home'})
        }
    }
}
</script>